/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package thinking.in.spring.boot.samples.externalized.configuration.bootstrap;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePropertySource;
import thinking.in.spring.boot.samples.externalized.configuration.util.PropertySourceUtils;

import java.io.IOException;
import java.util.stream.Stream;

/**
 * {@link ResourcePropertySource} 示例引导类
 *
 * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
 * @since 1.0.0
 */
@EnableAutoConfiguration
public class ResourcePropertySourceBootstrap {

    public static void main(String[] args) {
        // 调用工具类 PropertySourceUtils 获取 ResourcePropertySource
        ResourcePropertySource propertySource = PropertySourceUtils.getResourcePropertySource(
                "https://raw.githubusercontent.com/mercyblitz/tmp/master/remote.properties");
        // 输出 Properties 内容
        Stream.of(propertySource.getPropertyNames())                          // 将 String 转化为 Stream 对象
                .map(name -> name + " = " + propertySource.getProperty(name)) // 将 key 转化为 key = value 的形式
                .forEach(System.out::println);
    }
}
